//基本提交
function commit(postType, postData, url, successFunction, failFunction) {
    $.ajax({
        type: postType,
        data: postData,
        url: url,
        success: successFunction,
        error: failFunction
    });
}

function postCommit(postData, url, successFunction, failFunction) {
    return commit("POST", postData, url, successFunction, failFunction);
}

function putCommit(postData, url, successFunction, failFunction) {
    return commit("PUT", postData, url, successFunction, failFunction);
}

function getCommit(url, successFunction, failFunction) {
    alert("GET");
    return commit("GET", null, url, successFunction, failFunction);
}

function deleteCommit(url, successFunction, failFunction) {
    return commit("DELETE", null, url, successFunction, failFunction);
}
/*************************************************基本提交 end ***********************************************************/

//调用失败提示
function errorInfo(resultData) {
    alert("error:"+resultData.responseText);
}

//删除提示处理
function confirm(msg, invokeFunction) {
    layer.confirm(msg, {
        btn: ['是', '否'] //按钮
    }, function () {
        invokeFunction;
    }, function () {

    });
}

//删除记录
function delRecord(url, successFunction) {
    var msg = "是否删除该记录？";
    confirm(msg, deleteCommit(url, successFunction, errorInfo));
}


function dealSuccessFunction(resultData, dealFunction){
    // 1：勾号
    // 2：X号
    // 3：？号
    // 4：锁
    // 5：哭脸
    // 6：笑脸
    // 7：！号
    alert(resultData);
    var result = JSON.parse(resultData);
    if(result.code != 0){
        // layer.msg('删除成功', {
        //     btn: ['明白了', '知道了']
        //     ,yes: function(index, layero){
        //         layer.msg("按钮1回调,参数是:"+index)
        //     }
        //     ,btn2: function(index, layero){
        //         //按钮【按钮二】的回调
        //         layer.msg("按钮2回调,参数是:"+index)
        //         return false //开启该代码可禁止点击该按钮关闭
        //     }
        // });

        layer.msg(result.msg, {
            icon: 1,//提示的样式
            time: 4000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
            end:function(){
                dealFunction
            }
        });
        // layer.msg('删除成功', {icon: 1});
        // dealFunction
    }else{
        layer.msg(result.msg, {icon: 5,
            time: 6*1000
            // ,btn: ['关闭']
        });
    }
}


//异步刷新
function asyncRefreshDiv(divId) {
    $(divId).load(location.href+" " + divId);
}

//网页重新请求
function asyncRefresh(resultData, divId) {
    $(divId).html(resultData);
}